<?php
require_once ROOT_PATH . '/lib/models/surveys/Answers.php';//Chinh Nguyen add
require_once ROOT_PATH . '/lib/models/surveys/Options.php';//Chinh Nguyen add
require_once ROOT_PATH . '/lib/models/surveys/Questions.php';//Chinh Nguyen add
require_once ROOT_PATH . '/lib/models/surveys/Surveys.php';//Chinh Nguyen add  
require_once ROOT_PATH . '/FirePHPCore/FirePHP.class.php';
include ROOT_PATH.'/plugins/FusionChartsFree/Code/PHPClass/Includes/FusionCharts_Gen.php';

?>

<h2><?php echo $lang_Surveys_Dash_Board; ?><hr/></h2>
<form id="frmCancelLeave" name="frmCancelLeave" method="post" action="">
<table border="0" cellpadding="0" cellspacing="0">
  <thead>
  	<tr>
		<th class="tableTopLeft"></th>
		<th class="tableTopMiddle" width="10"></th>
		<th class="tableTopMiddle" ></th>
		<th class="tableTopMiddle"></th>
    	<th class="tableTopMiddle" width="400"></th>
		<th class="tableTopRight"></th>
	</tr>
  </thead>
  <tbody>
<?php
	$j = 0;
	$i = 0;
	if (is_array($records)&& count($records)) {		
		foreach ($records as $record) {
			//$surveyOwner = 
			if(!($j%2)) {$cssClass = 'odd';
			 } else {  	$cssClass = 'even'; }
			 $questions = Questions::getQuestionsBySurvey($record->getId());
			 	if(count($questions) >0){ ?>
				 	<tr>
					  	<td class="tableMiddleLeft"></td>
					    <td  colspan ="4" class="<?php echo $cssClass; ?>" style="font-weight:bold;font-color:red;"><?php echo $record->getSurveyName(); ?></td>				   	
						<td class="tableMiddleRight"></td>
					</tr>			 	
			 		<?php foreach($questions as $question){
					 	if(!($i%2)) {$cssClass = 'odd';
					 	} else {  	$cssClass = 'even'; }
					 	$i++;
					 	$questionType= $question->getAnswerType();
				 	
					 	//$options = Options::getOptionsByQuestions($question->getId());
					 	$answers = Answers::getAnswersByQuestionSurvey($record->getId(),$question->getId());
				 	
				 	?>
						 <tr>
						  	<td class="tableMiddleLeft"></td>
						  	<td></td>
						    <td colspan ="3" class="<?php echo $cssClass; ?>" style="color:blue;font-size:12px;"><?php echo $question->getText(); ?></td>
							<td class="tableMiddleRight"></td>
						 </tr>	
			 			<?php  if($questionType == 4 && count($answers)>0){
			 				foreach($answers as $answer){ ?>			 		
						 		<tr>
								  	<td class="tableMiddleLeft"></td>
								  	<td></td>
								  	<td></td>
								  	<td> <?php echo "[".$answer->getUser()."]:"; ?></td>
								    <td class=""><?php echo $answer->getValue(); ?></td>
									<td class="tableMiddleRight"></td>
							  	</tr>		
			 				<?php } 
			 				} else if($questionType == 1 && count($answers)>0){
			 					$answerY = $answerN =0; 
			 					foreach($answers as $answer){
			 						if($answer->getValue()==1)$answerY++;
			 						else $answerN++;
			 					}
			 					?>
			 					<tr>
								  	<td class="tableMiddleLeft"></td>
								  	<td></td>
								  	<td></td>
								  	<td> <?php echo "Yes/No"; ?></td>
								    <td class=""><?php echo $answerY."/".$answerN ;?></td>
									<td class="tableMiddleRight"></td>
							  	</tr>			 					 
		 				<?php } else if(($questionType == 2 || $questionType == 3)&& count($answers)>0){
			 					
			 					$options = Options::getOptionsByQuestions($question->getId());
			 					if(count($options)>0){
			 						$FC = new FusionCharts("Column3D","500","200");									  
								 	$FC->setSwfPath("../../plugins/FusionChartsFree/Charts/");
								  	$strParam="caption=".$question->getText().";xAxisName=;yAxisName=Count;decimalPrecision=0; formatNumberScale=0";
								  	$FC->setChartParams($strParam);
				 					foreach($options as $option){
				 						$answerCheck=0;
				 						foreach($answers as $answer){
				 							if($answer->getValue()==$option->getId())
				 								$answerCheck++;
				 						}												 						
				 						$FC->addChartData($answerCheck,"name=".$option->getText());
				 						?>
				 					<?php }				 							
								   
			 					}
			 					?>
			 					<tr>
								  	<td class="tableMiddleLeft"></td>
								  	<td></td>
								  	<td></td>								  	
								    <td colspan="2" class=""><?php $FC->renderChart(); ?></td>
									<td class="tableMiddleRight"></td>
							  	</tr>
						<?php }			 			
			 			}
			 		}
			 $j++;

?>
  

<?php
		}
	}else{ ?>
	 <tr>
	  	<td class="tableMiddleLeft"></td>
	  	<td></td>
	    <td class="">No survey available</td>
	    <td></td>
	     <td></td>
		<td class="tableMiddleRight"></td>
	  </tr>
		
	<?php }
?>
  </tbody>
  <tfoot>
  	<tr>
		<td class="tableBottomLeft"></td>
		<td class="tableBottomMiddle"></td>
		<td class="tableBottomMiddle"></td>
		<td class="tableBottomMiddle"></td>
		<td class="tableBottomMiddle"></td>
		<td class="tableBottomRight"></td>
	</tr>
  </tfoot>
</table>

